<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="sys.user.title" /></title>
  <meta name="decorator" content="list"/>
  <html:component name="bootstrap-treeview"/>
</head>
<body title="<spring:message code="sys.user.title" />">
<div class="row">
	<div class="col-sm-3 col-md-2" >
	   <view:treeview id="organizationTreeview" dataUrl="${adminPath}/sys/organization/bootstrapTreeData" onNodeSelected="organizationOnclick"></view:treeview>
	    <script type="text/javascript">
	       function organizationOnclick(event, node) {
	    	   //查询时间
	    	   //gridquery隐藏 查询标签概念，query,单独的query
	    	   $("input[name='organizationid']").val(node.href);
	    	   search('userGridIdGrid');
	       }
	   </script>
	</div>
	<div  class="col-sm-9 col-md-10">
		<grid:grid id="userGridId" url="${adminPath}/sys/user/ajaxList">
			<grid:column label="sys.common.key" hidden="true"   name="id" width="100"/>
			<grid:column label="sys.common.opt"  name="opt" formatter="button" width="100" sortable="false"/>
			<grid:button title="sys.role.dataPermission"  groupname="opt" function="updateObj" outclass="btn-warning" winwidth="300px" innerclass="fa-plus" url="${adminPath}/sys/user/dataPermission" />
			<grid:button groupname="opt" function="delete"/>
			<grid:query name="organizationid"  queryMode="hidden" />
		    <grid:column label="sys.user.realname"  name="realname"  query="true"  condition="like" />
		    <grid:column label="sys.user.username"  name="username"  query="true" condition="like"   />
			<grid:column label="sys.role.name"  name="rolename"  />
		    <grid:column label="sys.user.email"  name="email"  />
		    <grid:column label="sys.user.phone"  name="phone"  />
			<grid:column label="sys.user.status"  name="status" dict="userStatus" />
			<grid:toolbar title="sys.user.createuser" function="create"/>
		 	<grid:toolbar title="sys.user.updateuser" function="update"/>
			<grid:toolbar title="sys.user.modifypwd" icon="fa-database"  function="updateDialog" url="${adminPath}/sys/user/{id}/changePassword"  />
			<grid:toolbar title="锁定" icon="fa-file-text-o" onclick="lockOrUnlock('0')"/>
			<grid:toolbar title="解锁" icon="fa-file-text-o" btnclass="btn-warning" onclick="lockOrUnlock('1')"/>
			<grid:toolbar function="delete"/>
			<grid:toolbar  function="search"/>
			<grid:toolbar  function="reset"/>
		</grid:grid>
	</div>
</div>

<script>
	function lockOrUnlock(status) {
		var selectedRows = $("#userGridIdGrid").jqGrid('getGridParam','selarrrow');
		// 如果没有选择，提示
		if (selectedRows.length != 1) {
			top.layer.alert('请选择某个需要锁定或者解锁的用户!', {icon: 0, title:'警告'});
			return;
		}

		// POST请求解锁/锁定用户
		$.ajax({
			type: "POST",
			url: "${adminPath}/sys/user/lockOrUnlock",
			data: {
				id : $("#userGridIdGrid").jqGrid('getRowData', selectedRows[0]).id,
				status : status
			},
			traditional: true,
			success: function (data) {
				if (data.ret == 0) {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
					//刷新表单
					refreshTable("userGridIdGrid");
				}
				else {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
				}
			}
		});
	}
</script>
</body>
</html>